<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app"></div>
</body>

</html>
<script>
  function defineReactive(obj, key, val) {
    Object.defineProperty(obj, key, {
      get() {
        console.log('get', key);
        return val
      },
      set(newVal) {
        console.log('set', newVal);
        if (newVal != val) {
          val = newVal
          update()
        }
      }
    })
  }
  const app = document.querySelector("#app")
  const obj = {}

defineReactive(obj, 'foo', '')
function update() {
  app.innerHTML = obj.foo
}
setInterval(() => {
  obj.foo = new Date().toLocaleTimeString()
}, 1000);

</script>